<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改部门主数据')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-department-edit">
        <input id="id" name="id" type="hidden" th:value="${department.id}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">部门编码：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="deptCode" placeholder="请输入部门编码"
                       th:value="${department.deptCode}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">部门名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="deptName" placeholder="请输入部门名称"
                       th:value="${department.deptName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">部门简称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="deptAbbr" placeholder="请输入部门简称"
                       th:value="${department.deptAbbr}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">上级部门：</label>
            <div class="col-sm-8">
                <select name="parentId" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="parent : ${parent}" th:text="${parent.deptCN}"
                            th:value="${parent.id}" th:selected="${parent.id==department.parentId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">所属公司：</label>
            <div class="col-sm-8">
                <select name="compId" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="comp : ${comp}" th:text="${comp.compCN}"
                            th:value="${comp.id}" th:selected="${comp.id==department.compId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">部门负责人：</label>
            <div class="col-sm-8">
                <select name="director" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="employee : ${employee}" th:text="${employee.employeeCN}"
                            th:value="${employee.id}" th:selected="${employee.id==department.director}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">部门分管领导：</label>
            <div class="col-sm-8">
                <select name="leader" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="employee : ${employee}" th:text="${employee.employeeCN}"
                            th:value="${employee.id}" th:selected="${employee.id==department.leader}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公司状态：</label>
            <div class="col-sm-8">
                <div class="check-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                    <input type="radio" name="status" th:value="${dict.dictValue}"
                           th:text="${dict.dictLabel}" th:checked="${dict.dictValue==department.status+''}">
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "department";

    $("#form-department-edit").validate({
        rules: {
            onkeyup: false,
            deptCode: {
                remote: {
                    url: prefix + "/checkCodeUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "deptCode": function () {
                            return $("input[name='deptCode']").val();
                        },
                        "id": function () {
                            return $("input[name='id']").val();
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            }
        },
        messages: {
            "deptCode": {
                remote: "部门编号已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-department-edit").serializeArray();
            $.operate.save(prefix + "/edit", data);
        }
    }

</script>
</body>
</html>